// Copyright  2012 Petr TALLA. [petr.talla@gmail.com]
// This file is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY;  without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
// [http://www.gnu.org/copyleft/lesser.html]
//=============================================================================

package tc.crase.cmds;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;

import tc.common.registry.RegistrySys;
import tc.common.utility.GrView;
import tc.common.utility.TcDisplayTransf;
import tc.common.utility.TcDisplayXY;

import tc.crase.db.XattrGXY;
import tc.crase.sys.XobjectEx;
import tc.crase.view.ViewGraph;

public class CmdRemove extends CmdEx implements ActionListener {
	XattrGXY xo = null;
	Point2D.Double  xy;
	
	public CmdRemove () {
	}
	
	public void initializeDialog() {
		super.initializeDialog();
		setLabel("Rem. from Gr.");
		setHint("Select object in a graph. Next selection removes the object.");
		
		finalizeDialog();
	}
	
	public void enterPoint(Point pt, GrView view) {
		TcDisplayXY PT = new TcDisplayXY(new Point2D.Double(pt.x, pt.y), view.transf, TcDisplayXY.CoordSys.DEVICE);
		PT.transform(TcDisplayXY.CoordSys.WORLD);

		if (xo == null) {
			xo = ViewGraph.findNearestGi(view, PT.xy);
			xy = PT.xy;
		}
		else
		{	RegistrySys.registry.lock(); {
			  XobjectEx xoEx = (XobjectEx)xo.getParent();
			  xoEx.attrRemove(xo);
			} RegistrySys.registry.unlock();
			
			xo = null;			
		}
	}
	
	public void enterReset(GrView view) {
	}
	
	public void enterMove(Point pt, GrView view)  {
	}
	
	private void draw(Graphics g, TcDisplayTransf transf, Color background)
	{
	}
	
	public void actionPerformed(ActionEvent e) {
		if ("move_node".equals(e.getActionCommand())) {
		}
	}
}